home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / widdep.pro < prev    next >
Text File  |  1997-07-08  |  20KB  |  670 lines

  1. ;
  2. ; $Id: widdep.pro,v 1.13 1997/01/15 03:11:50 ali Exp $
  3. ;
  4. ;  WidDep
  5. ;   Dependent Dep object class definition.
  6. ;
  7. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  8. ;   Unauthorized reproduction prohibited.
  9. ;
  10. ; MODIFICATION HISTORY
  11. ;       Written by:     Joshua Goldstein,       12/93
  12. ;
  13.  
  14.  
  15. ;
  16. ;  DEP_Alloc
  17. ;       Allocate a dependent base object (if Ptr is NULL or just invalid)
  18. ;   There are 3 base object classes (MAIN,DEP, and BASE) so they call
  19. ;   a common routine to allocate base objects.
  20. ;
  21. PRO DEP_Alloc, Parent, Ptr
  22.   COMMON WidEd_Comm
  23.     IF KEYWORD_SET(Ptr) EQ 0 THEN BEGIN     ; Ptr already allocated
  24.         Ptr = WIDGET_BASE(GROUP=TopDlg)     ; Make a pointer
  25.         MakeBaseObj, Parent, Obj, "DEP"     ; Make a dep base object
  26.         Obj2Ptr, Obj, Ptr                   ; Store object in pointer
  27.         Dirty   = 1                         ; Things have changed since
  28.                                             ; last save.
  29.     ENDIF
  30. END
  31.  
  32.  
  33. ;
  34. ;  DEP_Copy
  35. ;       Copy the given dependent base object.
  36. ;   Remember to copy contents (children) as well.
  37. ;
  38. PRO DEP_Copy, Ptr, Copy
  39.     BASE_Copy, Ptr, Copy
  40. END
  41.  
  42. ;
  43. ;  DEP_Destroy
  44. ;   Release resources associated with the given object.  Recursively
  45. ;   remove children objects as well.
  46. ;
  47. PRO DEP_Destroy, Ptr
  48.     BASE_Destroy, Ptr       ; Does the same thing
  49. END
  50.  
  51.  
  52. ;
  53. ;  DEP_Kill
  54. ;   Base objects need to do things differently on a 'DONE' than
  55. ;   the more typical objects (c.f. MISC_Kill). Thus, a base object
  56. ;   specific kill routine.
  57. ;
  58. PRO DEP_Kill, Dlg
  59.  
  60.     WIDGET_CONTROL, Dlg, GET_UVALUE=Binfo, /NO_COPY
  61.  
  62.     IF WIDGET_INFO( BInfo.ObjPtr, /VALID) THEN BEGIN
  63.  
  64.         Ptr2Obj, Binfo.ObjPtr, Obj
  65.  
  66.         ;   We may not have any object associated with the
  67.         ;   dialog -- if we here as a result of the object
  68.         ;   being destroyed programmatically.  In that case,
  69.         ;   just don't do anything
  70.  
  71.         IF N_ELEMENTS(Obj) NE 0 THEN BEGIN
  72.             ;   Which dialog disappeared?
  73.             IF Obj.Dialog EQ Dlg THEN Obj.Dialog = 0        ; Dialog gone?
  74.             IF Obj.AttrDlg Eq Dlg THEN Obj.AttrDlg = 0      ; Add'l gone?
  75.             Obj2Ptr, Obj, Binfo.ObjPtr                      ; Save new state
  76.         ENDIF
  77.     ENDIF
  78. END
  79.  
  80.  
  81. ;
  82. ;  DEP_BarEvent
  83. ;   Event from the pull down menu don't have a <STRING> type UVALUE
  84. ;   to use for determining event type.  Instead the event.value is
  85. ;   usable.  However, it is easier to provide a separate event handler
  86. ;
  87. PRO DEP_BarEvent, Event
  88.  
  89.   COMMON WidEd_Comm
  90.  
  91.     WIDGET_CONTROL, Event.top, GET_UVALUE=Binfo, /NO_COPY
  92.  
  93.     IF Event.Value EQ 'Add.Hide Tool Bar' THEN BEGIN
  94.  
  95.         WIDGET_CONTROL, Binfo.ToolBar, MAP=0
  96.         WIDGET_CONTROL, Binfo.ToolId, SET_VALUE='Show Tool Bar'
  97.         WIDGET_CONTROL, Binfo.ToolId, SET_UVALUE='Add.Show Tool Bar' ; Hack
  98.         SetTag, Binfo.ObjPtr, "TB_Showing", 0
  99.  
  100.     ENDIF ELSE IF Event.Value EQ 'Add.Show Tool Bar' THEN BEGIN
  101.  
  102.         WIDGET_CONTROL, Binfo.ToolBar, MAP=1
  103.         WIDGET_CONTROL, Binfo.ToolId, SET_VALUE='Hide Tool Bar'
  104.         WIDGET_CONTROL, Binfo.ToolId, SET_UVALUE='Add.Hide Tool Bar' ; Hack
  105.         
  106.         SetTag, Binfo.ObjPtr, "TB_Showing", 1
  107.  
  108.     ENDIF ELSE BEGIN
  109.  
  110.         IF STRMID(Event.Value,0,4) EQ "Add." THEN BEGIN
  111.             Idx     = WHERE(STRMID(Event.Value,4,100) EQ AddList.Menu)
  112.             Build   = AddList[Idx].Class
  113.         ENDIF ELSE MESSAGE, 'Unprocessed event: ' + Event.Value
  114.  
  115.         ;   Allocate object and create a dialog box as well
  116.         CALL_PROCEDURE, Build+'_Build', Ptr, Binfo.ObjPtr
  117.  
  118.         ;   Add child to our child list.  Note that Base object
  119.         ;   do not get added to the active dialog box list
  120.         AddChild, Binfo.ObjPtr, Ptr, NO_CANCEL=(Build EQ 'Base')
  121.  
  122.     ENDELSE
  123.  
  124.     ;   Restore dialog box information
  125.     WIDGET_CONTROL, Event.top, SET_UVALUE=Binfo, /NO_COPY
  126. END
  127.  
  128.  
  129. ;
  130. ;  DEP_Event
  131. ;   Normal event handling routine for a dependent base object
  132. ;
  133. PRO DEP_Event, Event
  134.  
  135.   COMMON WidEd_Comm
  136.  
  137.     WIDGET_CONTROL, Event.Id, GET_UVALUE=Ev                 ; Get Event
  138.     WIDGET_CONTROL, Event.Top, GET_UVALUE=Binfo, /NO_COPY   ; Get Dialog Info
  139.     Ptr2Obj, Binfo.ObjPtr, Obj                              ; Get Object
  140.  
  141.     CASE Ev OF
  142.  
  143.     'Bbs':      BEGIN                   ; Base is a bulletin board
  144.         Obj.BaseType        = 0
  145.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=0
  146.         END
  147.     'Row':                BEGIN
  148.         Obj.BaseType        = 1
  149.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=1
  150.         END
  151.     'Column':        BEGIN
  152.         Obj.BaseType        = 2
  153.         WIDGET_CONTROL, Binfo.RowColId, SENSITIVE=1
  154.         END
  155.  
  156.     ;   user has set some characteristic of the object to a new value
  157.  
  158.     'NROW':         Obj.NRowCol     = Event.Value
  159.     'SPACE':        Obj.Space       = Event.Value
  160.     'XPAD':         Obj.XPad        = Event.Value
  161.     'YPAD':         Obj.YPad        = Event.Value
  162.     'NAME':         Obj.Name        = Event.Value
  163.     'XSCROLL':      Obj.XScrollSize = Event.Value
  164.     'YSCROLL':      Obj.YScrollSize = Event.Value
  165.  
  166.     ;   User wants to see the 'Additional Attributes' dialog
  167.     'ATTR':     DEP_BuildAttr, Event.Top, Binfo.ObjPtr, Obj
  168.  
  169.     ;   Additional Attribute Events
  170.     'XSIZE':        Obj.XSize       = Event.Value
  171.     'YSIZE':        Obj.YSize       = Event.Value
  172.     'XOFFSET':      Obj.XOffset     = Event.Value
  173.     'YOFFSET':      Obj.YOffset     = Event.Value
  174. ;   'EVENT_FUNC':   Obj.EventFunc   = Event.Value
  175.     'EVENT_PROC':   Obj.EventProc   = Event.Value
  176.     'GETFUNC':      Obj.GetFunc     = Event.Value
  177.     'SETPROC':      Obj.SetProc     = Event.Value
  178.     'KILLPROC':     Obj.KillProc    = Event.Value
  179.     'DO_TLB':       Obj.TLBEvents   = 1 - Obj.TLBEvents
  180.     'MAPPED':       Obj.BaseMapped  = 1 - Obj.BaseMapped
  181.     'DONE':         BEGIN
  182.                     Obj2Ptr, Obj, Binfo.ObjPtr
  183.                     WIDGET_CONTROL, Event.top, SET_UVALUE=Binfo, /NO_COPY
  184.                     WIDGET_CONTROL, Event.Top, /DESTROY
  185.                     RETURN
  186.                     END
  187.     ELSE:           MESSAGE, 'Unprocessed event: ' + Ev
  188.     ENDCASE
  189.  
  190.     Dirty   = 1     ; We've changed something since the last save
  191.  
  192.     SetNextFocus, Binfo, Event      ; Set next keyboard focus as necessary
  193.     Obj2Ptr, Obj, Binfo.ObjPtr      ; Put object back into pointer
  194.     WIDGET_CONTROL, Event.top, SET_UVALUE=Binfo, /NO_COPY
  195. END
  196.  
  197.  
  198. ;
  199. ; DEP_Build
  200. ;   Create a dialog for a dependent base object. If ptr is nil then
  201. ;   create the object as well.
  202. ;
  203. PRO DEP_Build, Ptr, Base
  204.  
  205.   COMMON WidEd_Comm
  206.  
  207.     DEP_Alloc, 0L, Ptr                      ; Allocate object if necessary
  208.     MgrName = 'WE_BASE' + STRTRIM(Ptr,2)    ; Create dialog box name
  209.     IF XRegistered(MgrName) THEN RETURN     ; See if it already exists
  210.  
  211.     Title   = 'Dependent Base: ' + GetId(Ptr)
  212.     Ptr2Obj, Ptr, Obj
  213.  
  214.     ;   Create dialog box
  215.  
  216.     Base            = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg)
  217.     Foci            = LONARR(7)
  218.  
  219.     ;   Menu bar contents
  220.  
  221.     Menu            = MakeAddMenu()
  222.     Menu[N_ELEMENTS(Menu)-1].flags  = 2
  223.     MenuBarDesc     = [ { CW_PDMENU_S, 3, 'Add' }, $
  224.                         { CW_PDMENU_S, 0, 'Hide Tool Bar' }, $
  225.                         Menu ]
  226.     If Obj.TB_Showing EQ 0 THEN MenuBarDesc[1].name = 'Show Tool Bar'
  227.     MenuBar         = CW_PDMENU(Base, MenuBarDesc, IDS=Ids, /RETURN_FULL_NAME)
  228.     ToolId          = Ids[1]
  229.  
  230.     BuildToolBar, Base, ToolBar
  231.  
  232.     BuildBaseType, Base, Obj, Foci, 0, RowColId, Btns
  233.     Base1   = WIDGET_BASE(Base, /COLUMN, EVENT_PRO='DEP_Event')
  234.     Foci[4] = Field(Base1, "Name:", Obj.Name, 'NAME', SIZE=50, /STRING)
  235.     BuildXY, Base, Obj, Foci, 5, /SIZE
  236.     Dummy   = WIDGET_BUTTON(Base, VALUE='More Attributes', $
  237.                 UVALUE='ATTR', EVENT_PRO='DEP_Event')
  238.  
  239.     Dummy   = WIDGET_LABEL(Base, VALUE=' ')
  240.     Dummy   = WIDGET_BUTTON(Base, VALUE='Done', UVALUE='DONE', $
  241.             EVENT_PRO='DEP_Event')
  242.  
  243.     DlgInfo = { $
  244.         Foci:       Foci, $
  245.         RowColId:   RowColId, $
  246.         ToolBar:    ToolBar, $
  247.         ToolId:     ToolId, $
  248.         ObjPtr:     Ptr $
  249.     }
  250.     Obj.Dialog  = Base
  251.  
  252.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  253.     WIDGET_CONTROL, Base, /REALIZE
  254.     WIDGET_CONTROL, Btns[Obj.BaseType], /SET_BUTTON
  255.     WIDGET_CONTROL, RowColId, SENSITIVE=(Obj.BaseType NE 0)
  256.  
  257.     WIDGET_CONTROL, ToolBar, MAP=Obj.TB_Showing
  258.  
  259.     XMANAGER, MgrName, Base, EVENT_HANDLER='DEP_BarEvent', CLEANUP='DEP_Kill'
  260.     Obj2Ptr, Obj, Ptr
  261. END
  262.  
  263.  
  264.  
  265. ;
  266. ;  DEP_Save
  267. ;   Store object information in a file. Identical to BASE_Save routine.
  268. ;
  269. PRO DEP_Save, Unit, Ptr
  270.     BASE_Save, Unit, Ptr
  271. END
  272.  
  273. ;
  274. ;  BASE_Restore
  275. ;   Read in a dependent base object (and its children) from a file
  276. ;
  277. PRO DEP_Restore, Unit, Parent, Ptr
  278.     urBASE_Restore, Unit, Parent, Ptr, "DEP"
  279. END
  280.  
  281. ;
  282. ;   DEP_BuildAttr
  283. ;       Object contains information about the base.  Ptr is needed
  284. ;   for object naming.  Routine builds the 'extra' dialog box that
  285. ;   base objects have.
  286. ;
  287. ;   This is a merged routine -- works for MAIN and DEP base objects
  288. ;
  289. PRO DEP_BuildAttr, Leader, Ptr, Obj
  290.  
  291.  
  292.     MgrName = 'WidBAttr' + STRTRIM(Ptr,2)   ; Create name an test for
  293.     IF XRegistered(MgrName) THEN RETURN     ; dialog already existing
  294.  
  295.     ;   Create Additional dialog
  296.  
  297.     Foci    = LONARR(8)
  298.     IF Obj.Type EQ 'MAIN' THEN BEGIN        ; MAIN Obj special case
  299.         Title   = 'Main Base Attributes'
  300.     ENDIF ELSE BEGIN
  301.         Title   = 'BASE ' + Obj.Id + ' Attributes'
  302.     ENDELSE
  303.  
  304.     Base    = WIDGET_BASE(  GROUP_LEADER=Leader, /COLUMN, TITLE=Title)
  305.  
  306.     ;   Event Related Info
  307.  
  308.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  309.     Lab     = WIDGET_LABEL(Base1, VALUE="Event Controls")
  310.  
  311. ;    Foci[0] = Field(Base1, "Event Function Name:", Obj.EventFunc, $
  312. ;                "EVENT_FUNC", SIZE=20, /STRING)
  313.     Foci[0] = Field(Base1, "Event Procedure Name:", Obj.EventProc, $
  314.                 "EVENT_PROC", SIZE=20, /STRING)
  315.     Foci[1] = Field(Base1, "Function Name for GET_VALUE:", Obj.GetFunc, $
  316.                 "GETFUNC", SIZE=20, /STRING)
  317.     Foci[2] = Field(Base1, "Procedure Name for SET_VALUE:", Obj.SetProc, $
  318.                 "SETPROC", SIZE=20, /STRING)
  319.     Foci[3] = Field(Base1, "Procedure Name for KILL_NOTIFY:", Obj.KillProc, $
  320.                 "KILLPROC", SIZE=20, /STRING)
  321.     Base2   = WIDGET_BASE(Base1, /NONEXCLUSIVE, /ROW)
  322.     Btn     = WIDGET_BUTTON(Base2,              $
  323.                     VALUE='Accept TLB Events',  $
  324.                     UVALUE='DO_TLB')
  325.  
  326.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  327.     Lab     = WIDGET_LABEL(Base1, VALUE="Window Appearance Controls")
  328.     BuildXY, Base1, Obj, Foci, 4, /SCROLL, /OFFSET
  329.     Base2   = WIDGET_BASE(Base1, /NONEXCLUSIVE, /ROW)
  330.     Btn     = WIDGET_BUTTON(Base2,              $
  331.                 VALUE='Base Starts Mapped', $
  332.                 UVALUE='MAPPED')
  333.     IF Obj.BaseMapped EQ 1 THEN WIDGET_CONTROL, Btn, /SET_BUTTON
  334.     Dummy   = WIDGET_LABEL(Base, VALUE=' ')
  335.     Dummy   = WIDGET_BUTTON(Base, VALUE='Done', UVALUE='DONE')
  336.  
  337.     DlgInfo     = { $
  338.         Foci:       Foci, $
  339.         ObjPtr:     Ptr $
  340.     }
  341.     Obj.AttrDlg = Base
  342.  
  343.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  344.     WIDGET_CONTROL, Base, /REALIZE
  345.     XMANAGER, MgrName, Base, EVENT_HANDLER=Obj.Type+'_Event', $
  346.             CLEANUP='DEP_Kill'
  347. END
  348.  
  349.  
  350. ;
  351. ;  TestDraw
  352. ;   When creating a preview I thought it would be nice to draw
  353. ;   something to the dialogs.  Thus, after creating a preview we
  354. ;   search the object hierarchy looking for drawables to put
  355. ;   plots in.
  356. ;
  357. PRO TestDraw, Ptr
  358.  
  359.     COMMON TestDraw_Comm, Seed
  360.  
  361.     Ptr2Obj, Ptr, Obj
  362.  
  363.     ;   We are only interested in 2 object types:
  364.     ;       Draws to draw in
  365.     ;       Base objects so that we can check their children
  366.  
  367.     CASE TAG_NAMES(Obj, /STRUCTURE) OF
  368.  
  369.     'WE_BASE': BEGIN
  370.         Child       = Obj.Children
  371.         WHILE Child NE 0L DO BEGIN
  372.             TestDraw, Child
  373.             Child   = NextPtr(Child)
  374.         ENDWHILE
  375.         END
  376.     'WE_DRAW': BEGIN
  377.         WIDGET_CONTROL, Obj.DrawId, GET_VALUE=WinId
  378.         WSET, WinId
  379.  
  380.         CASE (FIX(Randomu(Seed,1) * 4))[0] OF
  381.         0:      PLOT,[0,1],TITLE='Sample Plot'
  382.         1:      SURFACE, DIST( (FIX(Randomu(Seed,1)*10))[0] + 2 ), $
  383.                         TITLE='Sample Surface'
  384.         2:      PLOT,sin(findgen(100)/5)/exp(findgen(100)/50), $
  385.                         TITLE='Sample Plot'
  386.         3:      PLOT, Randomu(Seed,10), TITLE='Sample Plot'
  387.         ENDCASE
  388.         END
  389.     ELSE:           ; Do nothing
  390.     ENDCASE
  391.     Obj2Ptr, Obj, Ptr
  392. END
  393.  
  394.  
  395. ;
  396. ;  DEP_Generate
  397. ;   Create a dependent (or MAIN) base object and its children
  398. ;   for previewing.
  399. ;
  400. PRO DEP_Generate, Ptr, Id, Offset
  401.  
  402.   COMMON WidEd_Comm  
  403.  
  404.     Ptr2Obj, Ptr, Obj
  405.  
  406.     Id  = 0L            ; Prevent EXECUTE from creating a new variable
  407.  
  408.     ;   Generate command string
  409.  
  410.     Cmd = 'Id = WIDGET_BASE(GROUP_LEADER=' + STRTRIM(TopDlg,2)
  411.  
  412. ;   Tried allowing the user to resize a top level base and having
  413. ;   that affect the base's size.  I didn't like it so I have removed
  414. ;   that ability (c.f. wided.pro)
  415. ;   Cmd = Cmd + ",/TLB_SIZE_EVENTS"
  416.  
  417.     SAddCmd, Cmd, Obj.Name, 'TITLE'
  418.     IAddCmd, Cmd, Obj.FrameSize, 'FRAME'
  419.     IAddCmd, Cmd, Obj.XSize, 'XSIZE'
  420.     IAddCmd, Cmd, Obj.YSize, 'YSIZE'
  421.     IAddCmd, Cmd, Obj.XOffset, 'XOFFSET'
  422.     IAddCmd, Cmd, Obj.YOffset, 'YOFFSET'
  423.     IAddCmd, Cmd, Obj.XScrollSize, 'X_SCROLL_SIZE'
  424.     IAddCmd, Cmd, Obj.YScrollSize, 'Y_SCROLL_SIZE'
  425.  
  426.  
  427.     ;   Row/Column
  428.  
  429.     IF Obj.BaseType EQ 1 THEN           $
  430.         IAddCmd, Cmd, Obj.NRowCol, 'ROW'    $
  431.     ELSE IF Obj.BaseType EQ 2 THEN      $
  432.         IAddCmd, Cmd, Obj.NRowCol, 'COLUMN'
  433.  
  434.     IAddCmd, Cmd, Obj.Space, 'SPACE'
  435.     IAddCmd, Cmd, Obj.XPad, 'XPAD'
  436.     IAddCmd, Cmd, Obj.YPad, 'YPAD'
  437.  
  438.     ; Create base by running command string we just built
  439.  
  440.     IF EXECUTE(Cmd+')') NE 1 THEN BEGIN
  441.         Obj2Ptr, Obj, Ptr
  442.         MESSAGE,'Could not build base' + VarName(Ptr)
  443.     ENDIF
  444.  
  445.     ; Create any child widgets
  446.  
  447.     Child   = Obj.Children
  448.     WHILE Child NE 0L DO BEGIN
  449.         Ptr2Obj, Child, ChObj
  450.         Next    = ChObj.Next
  451.         Type    = ChObj.Type
  452.         Obj2Ptr, ChObj, Child
  453.         CALL_PROCEDURE, Type + "_Generate", Id, Child
  454.         Child   = Next
  455.     ENDWHILE
  456.  
  457.     WIDGET_CONTROL, Id, /REALIZE
  458.     WIDGET_CONTROL, Id, SET_UVALUE=Ptr
  459.  
  460.     ;XMANAGER, 'GenBase', Id, /JUST_REG (for TLB event)
  461.  
  462.     ;   If the user has moved the preview of the base and has not
  463.     ;   specified a position via the control panel then
  464.     ;   use the position of the previous preview as the location
  465.     ;   to rebuild a preview
  466.  
  467.     ;   If the user has not provided positions for the underlying
  468.     ;   objects, I create them in a cascade form
  469.  
  470.     IF Obj.XOffset EQ 0 AND Obj.YOffset EQ 0 THEN BEGIN
  471.         Xoff    = BaseXY[0, Offset]
  472.         Yoff    = BaseXY[1, Offset]
  473.  
  474.         IF Offset NE 0 AND Xoff EQ 0 AND Yoff EQ 0 THEN BEGIN
  475.             ;   Add frame fudge factors
  476.             Xoff    = Offset * 30 + 10
  477.             Yoff    = Offset * 20 + 30
  478.         ENDIF
  479.  
  480.         ;   Only move it if necessary.
  481.  
  482.         IF Xoff NE 0 OR Yoff NE 0 THEN $
  483.             WIDGET_CONTROL, Id, TLB_SET_XOFF=Xoff, TLB_SET_YOFF=Yoff
  484.     ENDIF
  485.  
  486.     XMANAGER, 'Gen', Id, /JUST_REG      ; Suck up events and ignore them
  487.  
  488.     Obj2Ptr, Obj, Ptr
  489.     TestDraw, Ptr                       ; Put a plot into drawables
  490. END
  491.  
  492.  
  493. ;
  494. ;  SaveEvent
  495. ;   Create an case statement in an event handler for the given object
  496. ;
  497. PRO SaveEvent, Unit, Ptr
  498.  
  499.     IF Ptr EQ 0 THEN RETURN
  500.  
  501.     Id  = GetId( Ptr )
  502.     Ptr2Obj, Ptr, Obj
  503.     UVal    = UValue(Obj, Ptr)
  504.     Type    = Obj.Type
  505.  
  506.     CASE Type OF
  507.  
  508.         'LABEL':            ; Labels don't generate events
  509.  
  510.         ;   Bases don't generate events but their children might
  511.         'BASE':     DoFList, Obj.Children, 'SaveEvent', Unit
  512.  
  513.         ;   Menus get an event function all their own
  514.         'PDMENU':           BEGIN
  515.             Name    = Type + Obj.Id
  516.             PRINTF, Unit, "  ; Event for ", Id
  517.             PRINTF, Unit, "  '", QString(UVal), "': ", Name, "_Event, Event"
  518.             END
  519.  
  520.         ;   Button groups have multiple formats (normal,exclusive,non-excl)
  521.         'BGROUP':   BEGIN
  522.             PRINTF, Unit, "  '", QString(UVal), "': BEGIN"
  523.             IF Obj.BaseExcl EQ 2 THEN BEGIN
  524.                 PRINTF, Unit, $
  525.                     "      IF Event.Select THEN Sel = 'On' ELSE Sel = 'Off'"
  526.                 Format='("      ",I0,": Print,''Button ",A," Turned '', Sel")'
  527.             ENDIF ELSE BEGIN
  528.                 Format='("      ",I0,": Print,''Button ",A," Pressed''")'
  529.             ENDELSE
  530.  
  531.             PRINTF, Unit, "      CASE Event.Value OF"
  532.  
  533.             GetValue, Obj, Names, "<Nil BGROUP>"
  534.             FOR I=0,N_ELEMENTS(Names)-1 DO BEGIN
  535.                 PRINTF, Unit, I, QString(Names[I]), FORMAT=Format
  536.             ENDFOR
  537.             PRINTF, Unit, "      ELSE: Message,'Unknown button pressed'"
  538.             PRINTF, Unit, "      ENDCASE"
  539.             PRINTF, Unit, "      END"
  540.             END
  541.  
  542.  
  543.         ;   All other items just need a simple skeleton
  544.         ELSE:   BEGIN
  545.             PRINTF, Unit, "  '", QString(UVal), "': BEGIN"
  546.             PRINTF, Unit, "      Print, 'Event for ", QString(Id), "'"
  547.             PRINTF, Unit, "      END"
  548.             END
  549.     ENDCASE
  550.  
  551.     Obj2Ptr, Obj, Ptr
  552. END
  553.  
  554.  
  555. ;
  556. ;  DEP_BaseEv
  557. ;   Write an event handler for a dependent base object
  558. ;
  559. PRO DEP_BaseEv, Unit, OldUnit, Ptr
  560.  
  561.     ; if the user has chosen a name for the event handler routine
  562.     ; we don't write the handler
  563.  
  564.     Id  = VarId(Ptr)
  565.  
  566.     Ptr2Obj, Ptr, Obj
  567.     IF Obj.EventFunc NE '' OR Obj.EventProc NE '' OR $
  568.        FindMagic(Id, Unit, OldUnit) THEN BEGIN
  569.         Obj2Ptr, Obj, Ptr
  570.         RETURN
  571.     ENDIF
  572.  
  573.     ; Write the routine header
  574.  
  575.     BeginMagic, Unit, Id
  576.  
  577.     PRINTF, Unit, FORMAT='(//"PRO ",A,"_Event, Event")', Id
  578.     PRINTF, Unit, FORMAT='(//A//A/)',           $
  579.     '  WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev',  $
  580.     '  CASE Ev OF '
  581.  
  582.     ;   Write an case statement for each child object
  583.  
  584.     DoFList, Obj.Children, 'SaveEvent', Unit
  585.  
  586.     ;   Might need a case statement for a top level base
  587.     ;   if the user desires it to receive TLB events.
  588.     ;   Normally a base does not generate(receive) events.
  589.  
  590.     IF Obj.TLBEvents THEN BEGIN
  591.         PRINTF, Unit, "  '", UValue(Obj,Ptr), "': BEGIN"
  592.         PRINTF, Unit, "      Print, 'Event for ", Id, "'"
  593.         PRINTF, Unit, "      END"
  594.     ENDIF
  595.  
  596.     Obj2Ptr, Obj, Ptr
  597.  
  598.     ;   Write routine footer
  599.  
  600.     PRINTF, Unit, '  ENDCASE'
  601.     PRINTF, Unit, 'END'
  602.  
  603.     EndMagic, Unit, Id
  604. END
  605.  
  606.  
  607. ;
  608. ;  GetDrawables
  609. ;   Scan object tree looking for drawables.  If we find one,
  610. ;   write code to extract the window-id of the draw widget.
  611. ;
  612. PRO GetDrawables, Unit, Ptr
  613.  
  614.     Ptr2Obj, Ptr, Obj
  615.  
  616.     CASE Obj.Type OF
  617.  
  618.     'MAIN': DoFList, Obj.Children, 'GetDrawables', Unit
  619.     'DEP':  DoFList, Obj.Children, 'GetDrawables', Unit
  620.     'BASE': DoFList, Obj.Children, 'GetDrawables', Unit
  621.     'DRAW': BEGIN
  622.         VarName = 'DRAW' + Obj.Id
  623.         PRINTF, Unit
  624.         PRINTF, Unit, '  ; Get drawable window index'
  625.         PRINTF, Unit
  626.         PRINTF, Unit, '  COMMON ', VarName, '_Comm, ', VarName, '_Id'
  627.         PRINTF, Unit, '  WIDGET_CONTROL, ', VarName, ', GET_VALUE=', $
  628.                 VarName, '_Id'
  629.         END
  630.     ELSE:
  631.     ENDCASE
  632.     Obj2Ptr, Obj, Ptr
  633. END
  634.  
  635.  
  636. ;
  637. ;  DEP_GenWid
  638. ;   Generate IDL code for creating a top level base widget
  639. ;
  640. PRO DEP_GenWid, Unit, Ptr, Leader
  641.  
  642.     Name    = VarId(Ptr)
  643.  
  644.     Ptr2Obj, Ptr, Obj
  645.  
  646.     ;   BASE000 = WIDGET_BASE(...
  647.  
  648.     XPRINTF, Unit, FORMAT='("  ",A," = WIDGET_BASE(")', Name, /NO_EOL
  649.     IF KEYWORD_SET(Leader) THEN BEGIN
  650.         XPRINTF, Unit, FORMAT='("GROUP_LEADER=",A)', VarId(Leader), /NO_EOL
  651.     ENDIF ELSE BEGIN
  652.         ; XPRINTF cannot have FORMAT w/o a positional arg
  653.         XPRINTF, Unit, FORMAT='(A)', "GROUP_LEADER=Group", /NO_EOL
  654.     ENDELSE
  655.  
  656.     ;   Create flag code
  657.     urBase_GenWid, Unit, Ptr, Obj, Name
  658.  
  659.     Obj2Ptr, Obj, Ptr
  660.  
  661.     ;   Create code to realize top level base
  662.     PRINTF, UNIT, FORMAT='("  WIDGET_CONTROL, ",A,", /REALIZE")', Name
  663.  
  664.     ;   Write code to get window ids
  665.     GetDrawables, Unit, Ptr
  666. END
  667.  
  668. PRO WidDep
  669. END
  670.